/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.evosoft.dao;

import com.evosoft.excepciones.NotEntityFoundException;
import com.evosoft.model.Persona;
import com.evosoft.model.Rol;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;

/**
 *
 * @author David
 */
public class RolDAO extends GenericDao<Rol>{
    private static RolDAO instance;

    public RolDAO() {
        super(Rol.class);
    }

    public synchronized static RolDAO getInstance() {
        if(instance == null){
            instance = new RolDAO();
        }
        
        return instance;
    }

    public List<Rol> obtenerPorEmpresa(int idEmpresa, EntityManager em) throws NotEntityFoundException {
        Query query = em.createQuery("SELECT r FROM Rol r WHERE r.empresa_id=:idEmpresa OR r.empresa_id=0");
        query.setParameter("idEmpresa", idEmpresa);
        
        List<Rol> roles = new ArrayList<Rol>();
        
        try {
            roles = (List) query.getResultList();
        } catch (Exception e) {
                e.printStackTrace();
        	throw (new NotEntityFoundException());
        }

        return roles;
    }
}
